//
//  NewsContentViewController.swift
//  AirTravel
//
//  Created by apple on 2021/11/15.
//

import UIKit
import HandyJSON
import WebKit
class NewsContentViewController: UIViewController {
    
    @IBOutlet weak var web: WKWebView!
    var newsID = ""

    var name = ""
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = name
        
        getData()
        // Do any additional setup after loading the view.
    }
    
    
        override func viewWillAppear(_ animated: Bool) {
            self.navigationController?.isNavigationBarHidden = true
        }
    
        override func viewWillDisappear(_ animated: Bool) {
            self.navigationController?.isNavigationBarHidden = false
        }
    
    func getData(){
        NetWorkRequest(API1.serviceGetNewsById(parameters: ["id" : newsID]), completion: {[weak self] (responseString) -> (Void) in
            guard let model = JSONDeserializer<NewsContentModel>.deserializeFrom(json: "\(responseString["data"])") else {
                return
            }
            self?.showConetent(str: model.content)
            
        }, failed: { (failedResutl) -> (Void) in
            print("服务器返回code不为0000啦~\(failedResutl)")
        }, errorResult: { () -> (Void) in
            print("网络异常,超时")
        })
    }
    
    func showConetent(str:String){
        self.web.loadHTMLString(str, baseURL: nil)
    }

}
